<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
		#wrap{
			position: relative;
		}
		#ul1{
			list-style: none;
			overflow: hidden;
		}
		#ul1 li{
			float: left;
			width: 80px;
			height: 40px;
			text-align: center;
			line-height: 40px;
		}
		#ul1 li a{
			display: block;
			width: 100%;
			height: 100%;
			text-decoration: none;
			color: black;
		}
		#slider{
			width: 80px;
			height: 2px;
			background-color: red;
			position: absolute;
			left: 0;
			bottom: 5px;
			transition: all 0.5s;
		}
	</style>	
</head>
<body>
	<div id="wrap">
		<ul id="ul1">
			<li><a href="#">按钮1</a></li>
			<li><a href="#">按钮2</a></li>
			<li><a href="#">按钮3</a></li>
			<li><a href="#">按钮4</a></li>
			<li><a href="#">按钮5</a></li>
		</ul>
		<div id="slider"></div>
	</div>
</body>
<script type="text/javascript">
	var aBtns = document.querySelectorAll('#ul1 li a');
	var slider = document.querySelector('#slider');
	var _width = aBtns[0].offsetWidth;
	for(var i = 0; i < aBtns.length; i ++){
		aBtns[i].index = i;
		aBtns[i].onmouseover = function(){
			slider.style.left = this.index * _width + 'px';
		}
	}
</script>
</html>











